{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "进行预测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     0.135699\n",
       "1     0.132886\n",
       "2     0.062267\n",
       "3     0.045839\n",
       "4     0.019826\n",
       "5     0.319714\n",
       "6     0.130967\n",
       "7     0.042673\n",
       "8     0.070981\n",
       "9     0.044678\n",
       "10    0.079525\n",
       "11    0.012257\n",
       "12    0.345971\n",
       "Name: value, dtype: float64"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import statsmodels.api as sm\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import pickle\n",
    "\n",
    "with open('data/model.pkl', 'rb') as f:\n",
    "    model = pickle.load(f)\n",
    "\n",
    "test_set = pd.read_csv('data/test_set.csv')\n",
    "\n",
    "x = np.column_stack((test_set.month,\n",
    "                     test_set.r4_value,\n",
    "                     test_set.r4_value**2,\n",
    "                     test_set.r4_value**3,\n",
    "                     test_set.r8_value,\n",
    "                     test_set.r12_value))\n",
    "X = sm.add_constant(x)\n",
    "y_pred = model.predict(X)\n",
    "diff =  np.abs(test_set.value - y_pred)/test_set.value\n",
    "diff"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "统计预测结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    13.000000\n",
       "mean      0.111022\n",
       "std       0.106694\n",
       "min       0.012257\n",
       "25%       0.044678\n",
       "50%       0.070981\n",
       "75%       0.132886\n",
       "max       0.345971\n",
       "Name: value, dtype: float64"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff.describe()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
